package be.vtk.partyApp.View;


import javax.swing.ImageIcon;

import javax.swing.JLabel;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.events.MenuDetectListener;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.List;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;



public class Design {

	protected Shell shell;
	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	private Text barcodevakje;
	private Text snummervakje;
	private static final ImageIcon CHECK_IMAGE = new ImageIcon(
		    Design.class.getResource("icon_check.png"));

	private static final ImageIcon FALSE_IMAGE = new ImageIcon(
		    Design.class.getResource("icon_false.png"));
	 private JLabel controleImageLabel;


	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Design window = new Design();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(767, 506);
		shell.setText("SWT Application");
		this.controleImageLabel = new JLabel(CHECK_IMAGE);
		
		
		ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
		toolBar.setBounds(50, 10, 180, 31);
		formToolkit.adapt(toolBar);
		formToolkit.paintBordersFor(toolBar);
		
		final Composite composite = formToolkit.createComposite(shell, SWT.NONE);
		composite.setBounds(32, 80, 701, 407);
		formToolkit.paintBordersFor(composite);
		
		Label lblBarcode = new Label(composite, SWT.NONE);
		lblBarcode.setBounds(10, 10, 70, 17);
		formToolkit.adapt(lblBarcode, true, true);
		lblBarcode.setText("Barcode");
		barcodevakje = new Text(composite, SWT.BORDER);
		

		barcodevakje.setBounds(78, 10, 285, 27);
		formToolkit.adapt(barcodevakje, true, true);
		
		Label lblSnummer = new Label(composite, SWT.NONE);
		lblSnummer.setBounds(0, 66, 70, 17);
		formToolkit.adapt(lblSnummer, true, true);
		lblSnummer.setText("s-nummer");
		
		snummervakje = new Text(composite, SWT.BORDER);
		snummervakje.setBounds(78, 69, 285, 27);
		formToolkit.adapt(snummervakje, true, true);
		
		Button btnOk = formToolkit.createButton(composite, "OK", SWT.NONE);
		btnOk.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println(barcodevakje.getText());
			}
		});
		btnOk.setBounds(407, 8, 91, 29);
		
		Button btnOk_1 = new Button(composite, SWT.NONE);
		btnOk_1.setBounds(407, 67, 91, 29);
		formToolkit.adapt(btnOk_1, true, true);
		btnOk_1.setText("OK");
		
		List genodigden = new List(composite, SWT.BORDER);
		genodigden.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDoubleClick(MouseEvent e) {
			}
		});
		genodigden.setBounds(51, 165, 222, 232);
		formToolkit.adapt(genodigden, true, true);
		
		Label lblGenodigden = formToolkit.createLabel(composite, "Genodigden", SWT.NONE);
		lblGenodigden.setBounds(51, 142, 91, 17);
		
		final Composite composite_1 = new Composite(composite, SWT.NONE);
		composite_1.setBounds(424, 142, 244, 265);
		formToolkit.adapt(composite_1);
		formToolkit.paintBordersFor(composite_1);
		composite_1.setVisible(false);
		
		Label lblGearriveerd = formToolkit.createLabel(composite_1, "Gearriveerd", SWT.NONE);
		lblGearriveerd.setBounds(10, 10, 112, 17);
		
		List gearriveerd = new List(composite_1, SWT.BORDER);
		gearriveerd.setBounds(30, 33, 172, 212);
		formToolkit.adapt(gearriveerd, true, true);
		
		displayPositiveCheckControle();
		
		

		
		ToolItem tltmVerkoop = new ToolItem(toolBar, SWT.NONE);
		tltmVerkoop.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(SelectionEvent e) {
				composite_1.setVisible(false);
			}
		});
		tltmVerkoop.setText("Verkoop");
		
		ToolItem tltmParty = new ToolItem(toolBar, SWT.NONE);
		tltmParty.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite_1.setVisible(true);
			}
		});
		tltmParty.setText("Party");
		
		Button btnUpdate = new Button(shell, SWT.NONE);
		btnUpdate.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				//update databases
			}
		});
		btnUpdate.setBounds(50, 45, 91, 29);
		formToolkit.adapt(btnUpdate, true, true);
		btnUpdate.setText("Update");
		
		

	}
	public void displayPositiveCheckControle() {
		    this.controleImageLabel.setIcon(CHECK_IMAGE);
	}
}
